﻿using System;
using System.Linq;
using System.Text;
using BT_Longnv.Controllers;
using BT_Longnv.Models;

namespace System.Web.Mvc.Html
{
    public static class MenuHelper
    {
        public static MvcHtmlString MenuAdmin(this HtmlHelper html)
        {
            StringBuilder result = new StringBuilder();
            TagBuilder li = new TagBuilder("li");
            TagBuilder ul = new TagBuilder("ul");
            TagBuilder a = new TagBuilder("a");
            TagBuilder li1 = new TagBuilder("li");
            TagBuilder ul1 = new TagBuilder("ul");
            TagBuilder a1 = new TagBuilder("a");
            var db = new BTVNContext();
            var listProduct = db.TableProduct.Select(item => new ProductModel
            {
                ProductId = item.ProductId,
                ProductName = item.ProductName,
            });
            var listCategory = db.TableCategory.Select(item => new CategoryModel
            {
                CategoryName = item.CategoryName,
                CategoryId = item.CategoryId
            }).Distinct();

            string categ="";
            foreach (var item in listCategory)
            {
                a = new TagBuilder("a");
                a1 = new TagBuilder("a");
                categ = item.CategoryName;
                a.InnerHtml += categ;
                li.InnerHtml += a;
                //a1.MergeAttribute("href", "/BTVN/ListProduct");

                //string product = "Iphone";
                //a1.InnerHtml += product;

                li1.InnerHtml += a1;

                ul1.InnerHtml += li1;
            }
                li.InnerHtml += ul1;
            
            result.Append(li);

            return MvcHtmlString.Create(result.ToString());
        }
    }
}